package com.lzt.yijian.mvp.view.activity;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.view.ViewPager;
import android.view.MenuItem;

import com.lzt.yijian.BottomNavigationViewHelper;
import com.lzt.yijian.R;
import com.lzt.yijian.adapter.MyFragmentPagerAdapter;
import com.lzt.yijian.mvp.base.BaseActivity;
import com.lzt.yijian.view.NoScrollViewPager;

import butterknife.BindView;

public class MainActivity extends BaseActivity {

    @BindView(R.id.navigation)
    BottomNavigationView mNavigation;
    @BindView(R.id.viewpager)
    NoScrollViewPager mViewpager;

    private String TAG = "MainActivity";

    private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
            = new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            switch (item.getItemId()) {
                case R.id.navigation_home:
                    mViewpager.setCurrentItem(0);
                    return true;
                case R.id.navigation_college:
                    mViewpager.setCurrentItem(1);
                    return true;
                case R.id.navigation_run:
                    mViewpager.setCurrentItem(2);
                    return true;
                case R.id.navigation_my:
                    mViewpager.setCurrentItem(3);
                    return true;
            }
            return false;
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        BottomNavigationViewHelper.disableShiftMode(mNavigation);
        mNavigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
    }

    private void initView() {
        mViewpager.setScroll(false);
        mViewpager.setAdapter(new MyFragmentPagerAdapter(getSupportFragmentManager()));
        mViewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                mNavigation.getMenu().getItem(position).setChecked(true);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
